package com.qzsoft.zhjd.monitoring.modules.videomonitor.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.monitoring.modules.videomonitor.dto.StreamInfoDto;
import com.qzsoft.zhjd.monitoring.modules.videomonitor.entity.VideoMonitorEntity;
import com.qzsoft.zhjd.monitoring.modules.videomonitor.service.VideoMonitorService;

/**
 * @ClassName VideoMonitorController
 * @Description 视频监控控制器
 * @author linhuawei
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/api/videoMonitor")
public class VideoMonitorController {

    @Autowired
    private VideoMonitorService videoMonitorService;

    /**
     * @Title page
     * @Description 获取视频列表
     * @param params 查询条件
     * @return 视频列表
     */
    @GetMapping("/page")
    public Result<IPage<VideoMonitorEntity>> page(@RequestParam Map<String, Object> params) {
        IPage<VideoMonitorEntity> page = videoMonitorService.page(params);
        return ResultUtils.ok(page);
    }
    
    /**
     * @Title save
     * @Description 添加视频监控
     * @param entity
     * @return
     */
    @PostMapping("/save")
    public Result<VideoMonitorEntity> save(@RequestBody VideoMonitorEntity entity){
        ValidatorUtils.validateEntity(entity);
        videoMonitorService.save(entity);
        return ResultUtils.ok(entity);
    }

    /**
     * @Title delete
     * @Description 删除视频监控
     * @param id 视频监控主键
     * @return 删除结果
     */
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable("id") String id) {
        videoMonitorService.removeById(id);
        return ResultUtils.ok();
    }

    /**
     * @Title getStreamInfo
     * @Description 获取播放信息
     * @param app
     * @param stream
     * @return
     */
    @GetMapping("/getStreamInfo")
    public Result<StreamInfoDto> getStreamInfo(@RequestParam(required = true) String app,
            @RequestParam(required = true) String stream) {
        StreamInfoDto data = videoMonitorService.getStreamInfo(app, stream, null);
        return ResultUtils.ok(data);
    }
}
